import grails.util.Environment
import com.th.*;
class BootStrap {

    def init = { servletContext ->
      
      switch(Environment.current) {
        
        case Environment.DEVELOPMENT:
        case Environment.PRODUCTION:
        
        if (!Tag.findByName("Grails")) {
          new Tag(name:'Grails').save()
          new Tag(name:'Java').save()
          new Tag(name:'Foursquare').save()
          new Tag(name:'SimpleGeo').save()
          new Tag(name:'Yelp').save()
          new Tag(name:'GSP').save()
          new Tag(name:'JSP').save()
          new Tag(name:'Ajax').save()
          new Tag(name:'JQuery').save()
          new Tag(name:'YUI').save()
          new Tag(name:'IPhone').save()
          new Tag(name:'Android').save()
          
        }
        if(!Project.findByName("prj1")) {
          def prj1 = new Project(name:"prj1",description  :'This is a sample project that uses a few technologies', sourceLocation:"http://abcd.com").save()
          def prj2 = new Project(name:"prj2",description:'This is a sample project that uses a few technologies', sourceLocation:"http://abcd.com").save()
          def prj3 = new Project(name:"prj3",description:'This is a sample project that uses a few technologies', sourceLocation:"http://abcd.com").save()
          def prj4 = new Project(name:"prj4",description:'This is a sample project that uses a few technologies', sourceLocation:"http://abcd.com").save()
          def prj5 = new Project(name:"prj5",description:'This is a sample project that uses a few technologies', sourceLocation:"http://abcd.com").save()
          
        
          //prj1
          def tu1 = new TechnologyUsed(expertiseLevel:4, description: "This technology is used in so and so file in so and so project").save()
          def tu2 = new TechnologyUsed(expertiseLevel:2, description: "This technology is used in so and so file in so and so project").save()
          def tu3 = new TechnologyUsed(expertiseLevel:3, description: "This technology is used in so and so file in so and so project").save()
          prj1.addToTechnologies(tu1)
          prj1.addToTechnologies(tu2)
          prj1.addToTechnologies(tu3)
          Tag.findByName("Grails").addToTechnologies(tu1)
          Tag.findByName("Java").addToTechnologies(tu3)
          Tag.findByName("Foursquare").addToTechnologies(tu2)
          
          //prj2
          def tu4 = new TechnologyUsed(expertiseLevel:4, description: "This technology is used in so and so file in so and so project").save()
          def tu5 = new TechnologyUsed(expertiseLevel:2, description: "This technology is used in so and so file in so and so project").save()
          prj2.addToTechnologies(tu3)
          prj2.addToTechnologies(tu4)
          Tag.findByName("Grails").addToTechnologies(tu4)
          Tag.findByName("Yelp").addToTechnologies(tu5)
          
          //prj3
          def tu6 = new TechnologyUsed(expertiseLevel:3, description: "This technology is used in so and so file in so and so project").save()
          def tu7 = new TechnologyUsed(expertiseLevel:5, description: "This technology is used in so and so file in so and so project").save()
          def tu8 = new TechnologyUsed(expertiseLevel:1, description: "This technology is used in so and so file in so and so project").save()
          prj3.addToTechnologies(tu6)
          prj3.addToTechnologies(tu7)
          prj3.addToTechnologies(tu8)
          Tag.findByName("Grails").addToTechnologies(tu6)
          Tag.findByName("Yelp").addToTechnologies(tu7)
          Tag.findByName("Android").addToTechnologies(tu8)
          
          
          //prj4
          def tu9 = new TechnologyUsed(expertiseLevel:1, description: "This technology is used in so and so file in so and so project").save()
          def tu10 = new TechnologyUsed(expertiseLevel:5, description: "This technology is used in so and so file in so and so project").save()
          def tu11 = new TechnologyUsed(expertiseLevel:1, description: "This technology is used in so and so file in so and so project").save()
          prj4.addToTechnologies(tu9)
          prj4.addToTechnologies(tu10)
          prj4.addToTechnologies(tu11)
          Tag.findByName("Grails").addToTechnologies(tu9)
          Tag.findByName("Yelp").addToTechnologies(tu10)
          Tag.findByName("GSP").addToTechnologies(tu11)
          
          //prj5
          def tu12 = new TechnologyUsed(expertiseLevel:1, description: "This technology is used in so and so file in so and so project").save()
          def tu13 = new TechnologyUsed(expertiseLevel:3, description: "This technology is used in so and so file in so and so project").save()
          prj2.addToTechnologies(tu12)
          prj2.addToTechnologies(tu13)
          Tag.findByName("GSP").addToTechnologies(tu12)
          Tag.findByName("Yelp").addToTechnologies(tu13)
          
          
          
          System.out.println("${Tag.count()} number of Tags present in the system")
          System.out.println("${Project.count()} number of projects present in the system")
          System.out.println("Project prj1 has ${prj1?.technologies?.size()} technologies")
          System.out.println("Project prj2 has ${prj2?.technologies?.size()} technologies")
          System.out.println("Project prj3 has ${prj3?.technologies?.size()} technologies")
          System.out.println("Project prj4 has ${prj4?.technologies?.size()} technologies")
          
        }
        
        
        
        break;
        }
    
    }
    def destroy = {
    }
}
